function getTime(num) {
	num = num * 1000;
	let date = new Date(num);
	let y = date.getFullYear();
	let MM = date.getMonth() + 1;
	MM = MM < 10 ? ('0' + MM) : MM; //月补0
	let d = date.getDate();
	d = d < 10 ? ('0' + d) : d; //天补0
	let h = date.getHours();
	h = h < 10 ? ('0' + h) : h; //小时补0
	let m = date.getMinutes();
	m = m < 10 ? ('0' + m) : m; //分钟补0
	let s = date.getSeconds();
	s = s < 10 ? ('0' + s) : s; //秒补0
	return y + '-' + MM + '-' + d + '  ' + h + ':' + m;
}

 
function poster(video) {
	video = video + '?x-oss-process=video/snapshot,t_1000,m_fast'
	return video
}

function getImg(path) { 
	if (path.indexOf("http") != -1) {
		return path;
	}
	path = uni.getStorageSync('img_url') + path
	return path
}

function getFace(url) {

	if (!url) {
		url = uni.getStorageSync('banmi_face') ? uni.getStorageSync('banmi_face') : '/static/icon/face.png';
	}
 
	if (url.indexOf("http") != -1) {
		return url;
	}
	url = uni.getStorageSync('img_url') + url
	return url
}

function getNickname(name) {
	if (!name) {
		return '默认昵称';
	}
	return name
}

function getTimer(stringTime) {
 
	var minute = 1000 * 60;
	var hour = minute * 60;
	var day = hour * 24;
	var week = day * 7;
	var month = day * 30;

	var time1 = new Date().getTime(); //当前的时间戳
	var time2 = stringTime * 1000; //指定时间的时间戳
	var time = time1 - time2;

	var result = null;
	if (time < 0) {
		return '刚刚';
	} else if (time / month >= 1) {
		result = parseInt(time / month) + "月前";
	} else if (time / week >= 1) {
		result = parseInt(time / week) + "周前";
	} else if (time / day >= 1) {
		result = parseInt(time / day) + "天前";
	} else if (time / hour >= 1) {
		result = parseInt(time / hour) + "小时前";
	} else if (time / minute >= 1) {
		result = parseInt(time / minute) + "分钟前";
	} else {
		result = "刚刚";
	}
	return result;
}

export default {
	getTime,
	poster,
	getImg,
	getFace,
	getNickname,
	getTimer,
	 
}